下面程序只保留 " 建套接字 —`connect`— 判返回 — 关闭 " 的连接式扫描结构。目标地址取命令行参数,缺省使用回环地址 `127.0.0.1`,代码内不出现任何外部目标。 ``` #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> /* 对 ip:port 发起一次 TCP 连接试探,开放返回 1,其余情况返回 0 */ static int probe(const char *ip, int port) { /* 创建 IPv4/TCP 套接字,失败返回 -1 */ int fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) { perror("socket"); return 0; } struct sockaddr_in addr; memset(&addr, 0,